<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

	<link rel="stylesheet" href="css/center.css">
	<link rel="stylesheet" href="css/menu.css">
	<link rel="stylesheet" href="css/contentMng.css">

	<!-- 分页css -->
	<link href="libs/vuePaging/VuePaging/zpageNav.css" rel="stylesheet" />

	<style type="text/css">
	</style>

	<link rel="shortcut icon" href="img/kai-toutiao.ico" />

	<title>媒体号作家中心 | 内容管理</title>
</head>

<body>
	<div id="mainPage" class="mybody">
		<!-- 顶部黑色头 -->
		<div id="whiteHeader" class="white-header">
			<div class="head_wrapper" @click="goIndex()">
				<img src="./img/kai-news-logo.png" class="center-logo"/>

				<div class="right-me-info">
					<img :src="userInfo.face" class="me-face"/>
					<span class="me-nickname">{{userInfo.nickname}}</span>
				</div>
			</div>
		</div>

		<!-- 页面容器 -->
		<div class="container">

			<div id="all-menus" class="all-menus">
				<ul class="menu-list shadow">
					<li class="">
						<div class="menu-title-wrapper">
							<img src="img/media-ico.png" class="word-ico"/>
							<div class="menu-title">媒体中心</div>
						</div>
						<ul>
							<li class="menu-item">
								<a href="contentMng.html" class="menu-item-select" v-if="userInfo.activeStatus == 1">内容管理</a>
								<a href="javascript:void(0);" class="menu-item-select" v-if="userInfo.activeStatus == 0">内容管理</a>
							</li>
							<!-- <li class="menu-item"><a href="javascript:void(0);" class="menu-item-select">主页</a></li> -->
							<li class="menu-item">
								<a href="createArticle.html" class="menu-item-default" v-if="userInfo.activeStatus == 1">发头条</a>
								<a href="javascript:void(0);" class="menu-item-default" v-if="userInfo.activeStatus == 0">发头条</a>
							</li>
							<li class="menu-item">
								<a href="commentMng.html" class="menu-item-default" v-if="userInfo.activeStatus == 1">评论管理</a>
								<a href="javascript:void(0);" class="menu-item-default" v-if="userInfo.activeStatus == 0">评论管理</a>
							</li>
							<!-- <li class="menu-item"><a href="javascript:void(0);" class="menu-item-default">打赏记录</a></li> -->
						</ul>
					</li>
				</ul>

				<ul class="menu-list shadow">
					<li class="">
						<div class="menu-title-wrapper">
							<img src="img/user-ico.png" class="word-ico"/>
							<div class="menu-title">个人账号</div>
						</div>
						<ul>
							<li class="menu-item">
								<a href="accountInfo.html" class="menu-item-default" v-if="userInfo.activeStatus == 1">账号设置</a>
								<a href="javascript:void(0);" class="menu-item-default" v-if="userInfo.activeStatus == 0">账号设置</a>
							</li>
							<li class="menu-item">
								<a href="myFans.html" class="menu-item-default" v-if="userInfo.activeStatus == 1">我的粉丝</a>
								<a href="javascript:void(0);" class="menu-item-default" v-if="userInfo.activeStatus == 0">我的粉丝</a>
							</li>
							<li class="menu-item">
								<a href="myFansCharts.html" class="menu-item-default" v-if="userInfo.activeStatus == 1">粉丝画像</a>
								<a href="javascript:void(0);" class="menu-item-default" v-if="userInfo.activeStatus == 0">粉丝画像</a>
							</li>

							<!-- <li class="menu-item"><a href="javascript:void(0);" class="menu-item-default">收益提现</a></li> -->
						</ul>
					</li>
				</ul>
			</div>

			<div class="main-page">
				<div class="search-box">
					<div class="status-wrapper">
						<div class="all-status">
							<span class="words-label">文章状态</span>
							<span :class="['words-status', articleStatusType == 0 ? 'status-selected' : 'status-default']" @click="queryByType(0)">全部</span>
							<span :class="['words-status', articleStatusType == 3 ? 'status-selected' : 'status-default']" @click="queryByType(3)">已发布</span>
							<span :class="['words-status', articleStatusType == 12 ? 'status-selected' : 'status-default']" @click="queryByType(12)">审核中</span>
							<span :class="['words-status', articleStatusType == 4 ? 'status-selected' : 'status-default']" @click="queryByType(4)">未通过</span>
							<span :class="['words-status', articleStatusType == 5 ? 'status-selected' : 'status-default']" @click="queryByType(5)">已撤回</span>

						</div>
						<div class="search-me">
							<div class="search-wrapper">
								<input type="test" v-model="searchContent" placeholder="请输入搜索关键字" class="search-input" @keyup.enter="submitSearch"/>
								<!-- <span class="search-btn">搜索</span> -->
								<span class="search-ico-wrapper">
									<img src="./img/icon-search.png" class="search-ico" @click="submitSearch"/>
								</span>
							</div>
						</div>
					</div>
					<div class="time-choose">
						<div class="words-label">时间选择</div>
						<div>
							<input type="text" class="input-date-picker" placeholder="开始日期 ~ 结束日期" id="choose-date">
						</div>
					</div>
				</div>

				<div id="article-list-wrapper" class="article-list-wrapper">
					<div class="article-list">

						<div class="every-article" v-for="(article, index) in articleList" :key="index">
							<img :src="article.articleCover" style="width: 175px; height: 125px;" v-show="article.articleType==1"/>

							<div class="main-content">
								<div class="basic-info">
									<span><a href="javascript:void(0);" target="_blank" class="article-link">{{article.title}}</a></span>
									<span class="counts-wrapper">
										<!-- TODO: 数字待定，后续做 -->
										<span>阅读 0 ⋅</span>
										<span>评论 0</span>
									</span>
									<span class="status-reviewing article-status" v-show="article.articleStatus==1 || article.articleStatus==2">审核中</span>
									<span class="status-published article-status" v-show="article.articleStatus==3">已发布</span>
									<span class="status-fail article-status" v-show="article.articleStatus==4">审核未通过</span>
									<span class="status-back article-status" v-show="article.articleStatus==5">已撤回</span>
									<span class="publish-time">
										<span v-show="article.isAppoint==1">预计发布时间：</span>
										{{formatData(article.publishTime)}}
									</span>
								</div>
								<div class="operation">
									<!-- <a href="javascript:void(0);" style="margin-top: 15px;">
										<img src="./img/icon-pen.png" class="oper-icon"/>
										<span class="oper-words">修改</span>
									</a> -->
									<a href="javascript:void(0);" style="margin-top: 8px;" @click="withdraw(article.id)" v-show="article.articleStatus==3">
										<img src="./img/icon-back.png" class="oper-icon"/>
										<span class="oper-words">撤回</span>
									</a>
									<a href="javascript:void(0);" style="margin-top: 8px;" @click="deleteArticle(article.id)" v-show="article.articleStatus==3 || article.articleStatus==4">
										<img src="./img/icon-delete.png" class="oper-icon"/>
										<span class="oper-words">删除</span>
									</a>
								</div>
							</div>
						</div>

					</div>

					<!-- 分页 start-->
					<div class="wrap" id="wrap">
						<zpagenav v-bind:page="page" v-bind:page-size="pageSize" v-bind:total="total"
							v-bind:max-page="maxPage"  v-on:pagehandler="doPaging">
						</zpagenav>
					</div>
					<!-- 分页 end-->

				</div>

			</div>

		</div>
	</div>

	<!-- footer -->
	<div class="footer">
		<div class="all-words-wrapper">
			<a class="footer-link" href="https://www.baidu.com" target="_blank">百度</a>
		</div>
	</div>
</body>

<script src="libs/vue.min.js"></script>
<script src="libs/axios.min.js"></script>
<script src="libs/jquery-1.7.2.min.js"></script>
<script src="libs/layDate-v5.0.9/laydate/laydate.js"></script>
<script src="libs/vuePaging/VuePaging/zpageNav.js"></script>
<script src="js/app.js"></script>
<script src="libs/moment-with-locales.min.js"></script>

<script type="text/javascript">

	var mainPage = new Vue({
		el: "#mainPage",
		data: {
			userInfo: {
				activeStatus: 0
			},

			searchContent: "",

			articleStatusType: 0,		// 查询的文章状态，默认0：全部
			startDateStr: "",
			endDateStr: "",

			articleList:[],

			page: 1, // 分页页数
			pageSize: 10, // 分页每页显示数量
			maxPage: 1, // 总页数
			total: 1, // 总记录数
		},
		mounted() {
			var me = this;
			// 初始化日历控件
			lay('#version').html('-v'+ laydate.v);
			laydate.render({
				elem: '#choose-date',
				range: true,
				done: function(value, date, endDate) { 	// 选择完后的回调
					console.log(value); 	//得到日期生成的值，如：2017-08-18
					console.log(date); 		//得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
					console.log(endDate); 	//得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。

					if(value){
						// 时间段查询
						var dateArr = value.split(" - ");
						var startDateStr = dateArr[0];
						var endDateStr = dateArr[1];
						console.log(startDateStr);
						console.log(endDateStr);
						me.startDateStr = startDateStr;
						me.endDateStr = endDateStr;

						var searchContent = me.searchContent;
						var statusType = me.articleStatusType;
						me.queryMyArticleList(1, 10, searchContent, statusType, startDateStr, endDateStr);
					}else{
						// 默认查询文章列表
						me.queryMyArticleList(1, 10, "", "", "", "");
					}
				}
			});
		},
		created() {
			// 判断用户登录
			app.judgeUserLoginStatus(this);

			// 默认查询文章列表
			this.queryMyArticleList(1, 10, "", "", "", "");
		},
		methods: {
			// 删除文章
			withdraw(articleId) {
				var confirm = window.confirm("确认撤回？");
				if (!confirm) {
					return;
				}

				var me = this;
				var utoken = app.getCookie("utoken");
				var uid = app.getCookie("uid");

				var articleServerUrl = app.articleServerUrl;
				axios.defaults.withCredentials = true;
				axios.post(articleServerUrl + "/article/withdraw?userId=" + uid +
															"&articleId=" + articleId,
				{},
				{
					headers: {
						'headerUserId': uid,
						'headerUserToken': utoken
					}
				})
				.then(res => {
					console.log(JSON.stringify(res.data));

					if (res.data.status == 200) {
						alert("撤回成功!");
						this.queryMyArticleList(1, 10, "", "", "", "");
					} else {
						alert(res.data.msg);
					}
				});
			},
			// 撤回文章
			deleteArticle(articleId) {
				console.log(articleId);
				var confirm = window.confirm("确认删除？");
				if (!confirm) {
					return;
				}

				var me = this;
				var utoken = app.getCookie("utoken");
				var uid = app.getCookie("uid");

				var articleServerUrl = app.articleServerUrl;
				axios.defaults.withCredentials = true;
				axios.post(articleServerUrl + "/article/delete?userId=" + uid +
															"&articleId=" + articleId,
				{},
				{
					headers: {
						'headerUserId': uid,
						'headerUserToken': utoken
					}
				})
				.then(res => {
					console.log(JSON.stringify(res.data));

					if (res.data.status == 200) {
						alert("删除成功!");
						this.queryMyArticleList(1, 10, "", "", "", "");
					} else {
						alert(res.data.msg);
					}
				});
			},
			// 查询文章列表
			queryMyArticleList(page, pageSize, keyword, status, startDate, endDate) {
				var me = this;
				me.page = page;

				var utoken = app.getCookie("utoken");
				var uid = app.getCookie("uid");

				var articleServerUrl = app.articleServerUrl;
				axios.defaults.withCredentials = true;
				axios.post(articleServerUrl + "/article/queryMyList?userId=" + uid +
															"&keyword=" + keyword +
															"&status=" + status +
															"&startDate=" + startDate +
															"&endDate=" + endDate +
															"&page=" + page +
															"&pageSize=" + pageSize,
				{},
				{
					headers: {
						'headerUserId': uid,
						'headerUserToken': utoken
					}
				})
				.then(res => {
					console.log(JSON.stringify(res.data));

					if (res.data.status == 200) {
						var grid = res.data.data;
						var articleList = grid.rows;
						me.articleList = articleList;

						var maxPage = grid.total; // 获得总页数
						var total = grid.records; // 获得总记录数

						this.maxPage = maxPage;
						this.total = total;
					} else {
						alert(res.data.msg);
					}
				});
			},
			// 根据状态类型查询
			queryByType(statusType) {
				this.articleStatusType = statusType;
				var startDateStr = this.startDateStr;
				var endDateStr = this.endDateStr;
				this.queryMyArticleList(1, 10, this.searchContent, statusType, startDateStr, endDateStr);
			},
			submitSearch() {
				var me = this;
				var searchContent = me.searchContent;
				var statusType = me.articleStatusType;
				var startDateStr = me.startDateStr;
				var endDateStr = me.endDateStr;
				this.queryMyArticleList(1, 10, searchContent, statusType, startDateStr, endDateStr);
			},

			// 分页实现方法 跳转到page页
			doPaging: function (page) {
				this.page = page;
				var searchContent = this.searchContent;
				var statusType = this.articleStatusType;
				var startDateStr = this.startDateStr;
				var endDateStr = this.endDateStr;
				this.queryMyArticleList(page, this.pageSize, searchContent, statusType, startDateStr, endDateStr);
			},
			// 格式化日期
			formatData(times) {
				var date = moment(times).format('YYYY-MM-DD hh:mm:ss');
				return date;
			},
			// 前往首页
			goIndex() {
				window.location = app.portalIndexUrl;
			}
		}
	});

</script>

</html>
